package whf.framework.ext.helper;

import java.io.InputStream;
import java.util.Properties;

import whf.framework.log.Log;
import whf.framework.log.LogFactory;

/**
 * @author king
 *
 */
public class DictHelperFactory {
	private Log log = LogFactory.getLog(DictHelperFactory.class);
	
	public static DictHelperFactory instance;
	
	private Properties props = new Properties();
	
	private DictHelperFactory(){
		try{
			InputStream is = DictHelperFactory.class.getResourceAsStream("DictHelper.config");
			props.load(is);
			is.close();
		} catch(Exception e){
			log.error(this, e);
		}
	}
	
	public static DictHelperFactory getInstance(){
		if(instance == null) instance = new DictHelperFactory();
		return instance;
	}
	
	public DictHelper getDictHelper(String code){
		String className = props.getProperty(code);
		try{
			DictHelper helper = (DictHelper)Class.forName(className).newInstance();
			return helper;
		} catch(ClassNotFoundException e){
			log.error(this, e);
			return null;
		} catch(Exception e){
			return null;
		}
	}
}
